<template>
    <div class="medical-records-info-container">
        <info-head v-model="infoData" @getData="getDRGData" @getHelper="getHelper" @searchData="searchData"/>
        <div class="info-content">
            <info-table v-model="infoData"/>
            <info-tool v-model="infoData" ref="infoTool" @getData="getDRGData"/>
        </div>
    </div>
</template>

<script>
    import {
        overviewDRGData,
        dataAnalysisDRGData,
        includeGroupDRGData,
        excludeGroupDRGData,
        notGroupDRGData,
        packageDRGData,
        MRTableData,
        MRHelperData,
        DRGNormalData,
        DRGNotlData,
        DRGExcludelData,
        comparsResData,
        billingListData,
        getMRStatDRG
    } from '@/api/medical-records-info/index'
    import InfoTable from '@/views/medical-records-info/components/InfoTable'
    import InfoHead from '@/views/medical-records-info/components/InfoHead'
    import InfoTool from '@/views/medical-records-info/components/InfoTool'

    export default {
        name: 'RecordsInfo',
        data () {
            return {
                // 所有数据
                infoData: {
                    codingError: [],
                    codingWaring: [],
                    noneCodingError: [],
                    noneCodingWaring: [],
                    allDeduction: [],
                    DRGsData: {},
                    resExamine: []
                },
                currentPage: 1,
                total: 1,
                // 使用储存的数据，不去请求
                useStoreData: false,
                useStoreTableData: false,
                useStoreHelperData: false,
                useStoreMRState: false
            }
        },
        created () {
            // tags判断入口是否从选项卡进入
            this.useStoreData = this.$route.query.tags === 'tags'
            this.useStoreTableData = this.$route.query.tags === 'tags'
            this.useStoreHelperData = this.$route.query.tags === 'tags'
            this.useStoreMRState = this.$route.query.tags === 'tags'
            this.getDRGData()
        },
        mounted () {
            let height = document.documentElement.clientHeight - 40 - 30 - 30 - 42 - 10
            if (document.documentElement.clientWidth < 1280) {
                height -= 16
            }
            document.getElementsByClassName('info-content')[0].style.height = height + 'px'
            window.onresize = () => {
                let height = document.documentElement.clientHeight - 40 - 30 - 30 - 42 - 10
                if (document.documentElement.clientWidth < 1280) {
                    height -= 16
                }
                document.getElementsByClassName('info-content')[0].style.height = height + 'px'
            }
            document.addEventListener('keydown', (event) => {
                if (event.keyCode === 8) {
                    return false
                }
            })
        },
        methods: {
            /**
             * 搜索病案号
             * @param bah 病案号
             */
            searchData (bah) {
                this.setGetStore(this.$route.name, {keyword: bah})
                this.getDRGData(bah)
            },
            /**
             * 获取页面数据
             * @param bah 病案号（通过检索查询）
             */
            getDRGData (bah) {
                let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                let overview = ['OverviewListInfo', 'OverviewDeathsInfo', 'OverviewAgainInfo', 'MRListInfoDRG', 'ServiceListInfo']
                let dataAnalysis = ['EfficiencyListInfo', 'SafetyListInfo', 'ExpensesListInfo']
                let params = {
                    hosDays: query.hosDays,
                    rehospital: query.rehospital || false,
                    patientState: query.patientState,
                    deathState: query.deathState,
                    pageSize: 1,
                    pageIndex: bah ? 1 : query.pageIndex,
                    keyword: query.keyword,
                    department: query.department,
                    depName: query.depName,
                    orgId: query.orgId,
                    start: query.start,
                    end: query.end,
                    orderBy: query.orderBy
                }
                params.patientState = this.$route.name === 'OverviewDeathsInfo' ? 1 : 0
                if (this.$route.name === 'ImportMRListInfoDRG') {
                    params.state = query.state
                    params.packageID = query.packageID
                }
                this.setGetStore(this.$route.name, params)
                if (overview.includes(this.$route.name)) {
                    switch (query.tab) {
                    case 'included':
                        this.getIncludeGroupDRGData(params)
                        break
                    case 'not':
                        this.getNotGroupDRGData(params)
                        break
                    case 'exclude':
                        this.getExcludeGroupDRGData(params)
                        break
                    default:
                        params.state = query.state
                        this.getOverviewDRGData(params)
                    }
                } else if (dataAnalysis.includes(this.$route.name)) {
                    this.getDataAnalysisDRGData(params)
                }
                switch (this.$route.name) {
                case 'ImportMRListInfoDRG':
                    this.getPackageDRGData(params)
                    break
                case 'NormalInfo':
                    this.getDRGNormalData()
                    break
                case 'NotIncludedInfo':
                    this.getDRGNotlData()
                    break
                case 'ExcludeGroupInfo':
                    this.getDRGExcludelData()
                    break
                case 'CompareResultsInfo':
                    this.getComparsResData()
                    break
                case 'BillingListInfo':
                    this.getBillingListData()
                    break
                }
            },
            /**
             * 查询DRG信息(总览列表/死亡例数/数据管理/服务能力-入组列表)
             * @param params 查询参数
             */
            getIncludeGroupDRGData (params) {
                if (this.getSession(this.$route.name, 'DRGData') && this.useStoreData) {
                    this.useStoreData = false
                    let res = this.getSession(this.$route.name, 'DRGData')
                    if (res.code.toString() === '200') {
                        if (res.data.rows.length) {
                            this.infoData.DRGsData = res.data.rows[0]
                            this.currentPage = res.data.index
                            this.total = res.data.total
                            let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                            let data = {
                                medicalRecordSign: this.infoData.DRGsData.medicalRecordSign,
                                hospitalTime: res.data.rows[0].hospitalTime,
                                isLast: true,
                                orgId: query.orgId
                            }
                            this.getMRData(data)
                            this.getMRHelperData(data)
                            this.getDataState(this.infoData.DRGsData.medicalRecordID)
                        } else {
                            this.$message.error('您搜索的病案号信息不存在')
                            this.setGetStore(this.$route.name, {keyword: ''})
                        }
                    }
                } else {
                    includeGroupDRGData(params).then(res => {
                        this.useStoreData = false
                        this.setSession(this.$route.name, {DRGData: res})
                        if (res.code.toString() === '200') {
                            if (res.data.rows.length) {
                                this.infoData.DRGsData = res.data.rows[0]
                                this.currentPage = res.data.index
                                this.total = res.data.total
                                let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                                let data = {
                                    medicalRecordSign: this.infoData.DRGsData.medicalRecordSign,
                                    hospitalTime: res.data.rows[0].hospitalTime,
                                    isLast: true,
                                    orgId: query.orgId
                                }
                                this.getMRData(data)
                                this.getMRHelperData(data)
                                this.getDataState(this.infoData.DRGsData.medicalRecordID)
                            } else {
                                this.$message.error('您搜索的病案号信息不存在')
                                this.setGetStore(this.$route.name, {keyword: ''})
                            }
                        }
                    })
                }
            },
            /**
             * 查询DRG信息(总览列表/死亡例数/数据管理/服务能力-未入组列表)
             * @param params 查询参数
             */
            getNotGroupDRGData (params) {
                if (this.getSession(this.$route.name, 'DRGData') && this.useStoreData) {
                    this.useStoreData = false
                    let res = this.getSession(this.$route.name, 'DRGData')
                    if (res.code.toString() === '200') {
                        if (res.data.rows.length) {
                            this.infoData.DRGsData = res.data.rows[0]
                            this.currentPage = res.data.index
                            this.total = res.data.total
                            let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                            let data = {
                                medicalRecordSign: this.infoData.DRGsData.medicalRecordSign,
                                hospitalTime: res.data.rows[0].hospitalTime,
                                isLast: true,
                                orgId: query.orgId
                            }
                            this.getMRData(data)
                            this.getMRHelperData(data)
                            this.getDataState(this.infoData.DRGsData.medicalRecordID)
                        } else {
                            this.$message.error('您搜索的病案号信息不存在')
                            this.setGetStore(this.$route.name, {keyword: ''})
                        }
                    }
                } else {
                    notGroupDRGData(params).then(res => {
                        this.useStoreData = false
                        this.setSession(this.$route.name, {DRGData: res})
                        if (res.code.toString() === '200') {
                            if (res.data.rows.length) {
                                this.infoData.DRGsData = res.data.rows[0]
                                this.currentPage = res.data.index
                                this.total = res.data.total
                                let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                                let data = {
                                    medicalRecordSign: this.infoData.DRGsData.medicalRecordSign,
                                    hospitalTime: res.data.rows[0].hospitalTime,
                                    isLast: true,
                                    orgId: query.orgId
                                }
                                this.getMRData(data)
                                this.getMRHelperData(data)
                                this.getDataState(this.infoData.DRGsData.medicalRecordID)
                            } else {
                                this.$message.error('您搜索的病案号信息不存在')
                                this.setGetStore(this.$route.name, {keyword: ''})
                            }
                        }
                    })
                }
            },
            /**
             * 查询DRG信息(总览列表/死亡例数/数据管理/服务能力-排除组列表)
             * @param params 查询参数
             */
            getExcludeGroupDRGData (params) {
                if (this.getSession(this.$route.name, 'DRGData') && this.useStoreData) {
                    this.useStoreData = false
                    let res = this.getSession(this.$route.name, 'DRGData')
                    if (res.code.toString() === '200') {
                        if (res.data.rows.length) {
                            this.infoData.DRGsData = res.data.rows[0]
                            this.currentPage = res.data.index
                            this.total = res.data.total
                            let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                            let data = {
                                medicalRecordSign: this.infoData.DRGsData.medicalRecordSign,
                                hospitalTime: res.data.rows[0].hospitalTime,
                                isLast: true,
                                orgId: query.orgId
                            }
                            this.getMRData(data)
                            this.getMRHelperData(data)
                            this.getDataState(this.infoData.DRGsData.medicalRecordID)
                        } else {
                            this.$message.error('您搜索的病案号信息不存在')
                            this.setGetStore(this.$route.name, {keyword: ''})
                        }
                    }
                } else {
                    excludeGroupDRGData(params).then(res => {
                        this.useStoreData = false
                        this.setSession(this.$route.name, {DRGData: res})
                        if (res.code.toString() === '200') {
                            if (res.data.rows.length) {
                                this.infoData.DRGsData = res.data.rows[0]
                                this.currentPage = res.data.index
                                this.total = res.data.total
                                let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                                let data = {
                                    medicalRecordSign: this.infoData.DRGsData.medicalRecordSign,
                                    hospitalTime: res.data.rows[0].hospitalTime,
                                    isLast: true,
                                    orgId: query.orgId
                                }
                                this.getMRData(data)
                                this.getMRHelperData(data)
                                this.getDataState(this.infoData.DRGsData.medicalRecordID)
                            } else {
                                this.$message.error('您搜索的病案号信息不存在')
                                this.setGetStore(this.$route.name, {keyword: ''})
                            }
                        }
                    })
                }
            },
            /**
             * 查询DRG信息(总览列表/死亡例数/数据管理/服务能力-全部列表)
             * @param params 查询参数
             */
            getOverviewDRGData (params) {
                if (this.getSession(this.$route.name, 'DRGData') && this.useStoreData) {
                    this.useStoreData = false
                    let res = this.getSession(this.$route.name, 'DRGData')
                    if (res.code.toString() === '200') {
                        if (res.data.rows.length) {
                            this.infoData.DRGsData = res.data.rows[0]
                            this.currentPage = res.data.index
                            this.total = res.data.total
                            let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                            let data = {
                                medicalRecordSign: this.infoData.DRGsData.medicalRecordSign,
                                hospitalTime: res.data.rows[0].hospitalTime,
                                isLast: true,
                                orgId: query.orgId
                            }
                            this.getMRData(data)
                            this.getMRHelperData(data)
                            this.getDataState(this.infoData.DRGsData.medicalRecordID)
                        } else {
                            this.$message.error('您搜索的病案号信息不存在')
                            this.setGetStore(this.$route.name, {keyword: ''})
                        }
                    }
                } else {
                    overviewDRGData(params).then(res => {
                        this.useStoreData = false
                        this.setSession(this.$route.name, {DRGData: res})
                        if (res.code.toString() === '200') {
                            if (res.data.rows.length) {
                                this.infoData.DRGsData = res.data.rows[0]
                                this.currentPage = res.data.index
                                this.total = res.data.total
                                let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                                let data = {
                                    medicalRecordSign: this.infoData.DRGsData.medicalRecordSign,
                                    hospitalTime: res.data.rows[0].hospitalTime,
                                    isLast: true,
                                    orgId: query.orgId
                                }
                                this.getMRData(data)
                                this.getMRHelperData(data)
                                this.getDataState(this.infoData.DRGsData.medicalRecordID)
                            } else {
                                this.$message.error('您搜索的病案号信息不存在')
                                this.setGetStore(this.$route.name, {keyword: ''})
                            }
                        }
                    })
                }
            },
            /**
             * 查询DRG信息(医疗安全/效率/费用列表)
             * @param params 查询参数
             */
            getDataAnalysisDRGData (params) {
                if (this.getSession(this.$route.name, 'DRGData') && this.useStoreData) {
                    this.useStoreData = false
                    let res = this.getSession(this.$route.name, 'DRGData')
                    if (res.code.toString() === '200') {
                        if (res.data.rows.length) {
                            this.infoData.DRGsData = res.data.rows[0]
                            this.currentPage = res.data.index
                            this.total = res.data.total
                            let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                            let data = {
                                medicalRecordSign: this.infoData.DRGsData.medicalRecordSign,
                                hospitalTime: res.data.rows[0].hospitalTime,
                                isLast: true,
                                orgId: query.orgId
                            }
                            this.getMRData(data)
                            this.getMRHelperData(data)
                            this.getDataState(this.infoData.DRGsData.medicalRecordID)
                        } else {
                            this.$message.error('您搜索的病案号信息不存在')
                            this.setGetStore(this.$route.name, {keyword: ''})
                        }
                    }
                } else {
                    dataAnalysisDRGData(params).then(res => {
                        this.useStore = false
                        this.setSession(this.$route.name, {DRGData: res})
                        if (res.code.toString() === '200') {
                            if (res.data.rows.length) {
                                this.infoData.DRGsData = res.data.rows[0]
                                this.currentPage = res.data.index
                                this.total = res.data.total
                                let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                                let data = {
                                    medicalRecordSign: this.infoData.DRGsData.medicalRecordSign,
                                    hospitalTime: res.data.rows[0].hospitalTime,
                                    isLast: true,
                                    orgId: query.orgId
                                }
                                this.getMRData(data)
                                this.getMRHelperData(data)
                                this.getDataState(this.infoData.DRGsData.medicalRecordID)
                            } else {
                                this.$message.error('您搜索的病案号信息不存在')
                                this.setGetStore(this.$route.name, {keyword: ''})
                            }
                        }
                    })
                }
            },
            /**
             * 查询DRG信息(病案包列表)
             * @param params 查询参数
             */
            getPackageDRGData (params) {
                if (this.getSession(this.$route.name, 'DRGData') && this.useStoreData) {
                    this.useStoreData = false
                    let res = this.getSession(this.$route.name, 'DRGData')
                    if (res.code.toString() === '200') {
                        if (res.data.rows.length) {
                            this.infoData.DRGsData = res.data.rows[0]
                            this.currentPage = res.data.index
                            this.total = res.data.total
                            let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                            let data = {
                                medicalRecordSign: this.infoData.DRGsData.medicalRecordSign,
                                hospitalTime: res.data.rows[0].hospitalTime,
                                isLast: true,
                                orgId: query.orgId
                            }
                            this.getMRData(data)
                            this.getMRHelperData(data)
                            this.getDataState(this.infoData.DRGsData.medicalRecordID)
                        } else {
                            this.$message.error('您搜索的病案号信息不存在')
                            this.setGetStore(this.$route.name, {keyword: ''})
                        }
                    }
                } else {
                    packageDRGData(params).then(res => {
                        this.useStoreData = false
                        this.setSession(this.$route.name, {DRGData: res})
                        if (res.code.toString() === '200') {
                            if (res.data.rows.length) {
                                this.infoData.DRGsData = res.data.rows[0]
                                this.currentPage = res.data.index
                                this.total = res.data.total
                                let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                                let data = {
                                    medicalRecordSign: this.infoData.DRGsData.medicalRecordSign,
                                    hospitalTime: res.data.rows[0].hospitalTime,
                                    isLast: true,
                                    orgId: query.orgId
                                }
                                this.getMRData(data)
                                this.getMRHelperData(data)
                                this.getDataState(this.infoData.DRGsData.medicalRecordID)
                            } else {
                                this.$message.error('您搜索的病案号信息不存在')
                                this.setGetStore(this.$route.name, {keyword: ''})
                            }
                        }
                    })
                }
            },
            /**
             * 查询drg入组分析正常
             */
            getDRGNormalData () {
                let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                let params = {
                    department: query.department,
                    name: query.name,
                    feeType: query.feeType,
                    mdc: query.mdc,
                    groupType: query.groupType,
                    xftj: query.xftj,
                    drgCodeName: query.drgCodeName,
                    weightStart: query.weightStart,
                    weightEnd: query.weightEnd,
                    riskLevel: query.riskLevel,
                    start: query.start,
                    end: query.end,
                    orgID: query.orgId,
                    pageIndex: query.pageIndex,
                    pageSize: 1,
                    keyword: query.keyword,
                    orderBy: query.orderBy
                }
                if (this.getSession(this.$route.name, 'DRGData') && this.useStoreData) {
                    this.useStoreData = false
                    let res = this.getSession(this.$route.name, 'DRGData')
                    if (res.code.toString() === '200') {
                        if (res.data.rows.length) {
                            this.infoData.DRGsData = res.data.rows[0]
                            this.currentPage = res.data.index
                            this.total = res.data.total
                            let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                            let data = {
                                medicalRecordSign: this.infoData.DRGsData.medicalRecordSign,
                                hospitalTime: res.data.rows[0].hospitalTime,
                                isLast: true,
                                orgId: query.orgId
                            }
                            this.getMRData(data)
                            this.getMRHelperData(data)
                            this.getDataState(this.infoData.DRGsData.medicalRecordID)
                        } else {
                            this.$message.error('您搜索的病案号信息不存在')
                            this.setGetStore(this.$route.name, {keyword: ''})
                        }
                    }
                } else {
                    DRGNormalData(params).then(res => {
                        this.useStoreData = false
                        this.setSession(this.$route.name, {DRGData: res})
                        if (res.code.toString() === '200') {
                            if (res.data.rows.length) {
                                this.infoData.DRGsData = res.data.rows[0]
                                this.currentPage = res.data.index
                                this.total = res.data.total
                                let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                                let data = {
                                    medicalRecordSign: this.infoData.DRGsData.medicalRecordSign,
                                    hospitalTime: res.data.rows[0].hospitalTime,
                                    isLast: true,
                                    orgId: query.orgId
                                }
                                this.getMRData(data)
                                this.getMRHelperData(data)
                                this.getDataState(this.infoData.DRGsData.medicalRecordID)
                            } else {
                                this.$message.error('您搜索的病案号信息不存在')
                                this.setGetStore(this.$route.name, {keyword: ''})
                            }
                        }
                    })
                }
            },
            /**
             * 查询drg入组分析未入组
             */
            getDRGNotlData () {
                let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                let params = {
                    department: query.department,
                    name: query.name,
                    surgeryCode: query.surgeryCode,
                    diagnosisCode: query.diagnosisCode,
                    gType: query.gType,
                    exRule: query.exRule,
                    start: query.start,
                    end: query.end,
                    orgID: query.orgId,
                    pageIndex: query.pageIndex,
                    pageSize: 1,
                    keyword: query.keyword,
                    orderBy: query.orderBy
                }
                if (this.getSession(this.$route.name, 'DRGData') && this.useStoreData) {
                    this.useStoreData = false
                    let res = this.getSession(this.$route.name, 'DRGData')
                    if (res.code.toString() === '200') {
                        if (res.data.rows.length) {
                            this.infoData.DRGsData = res.data.rows[0]
                            this.currentPage = res.data.index
                            this.total = res.data.total
                            let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                            let data = {
                                medicalRecordSign: this.infoData.DRGsData.medicalRecordSign,
                                hospitalTime: res.data.rows[0].hospitalTime,
                                isLast: true,
                                orgId: query.orgId
                            }
                            this.getMRData(data)
                            this.getMRHelperData(data)
                            this.getDataState(this.infoData.DRGsData.medicalRecordID)
                        } else {
                            this.$message.error('您搜索的病案号信息不存在')
                            this.setGetStore(this.$route.name, {keyword: ''})
                        }
                    }
                } else {
                    DRGNotlData(params).then(res => {
                        this.useStoreData = false
                        this.setSession(this.$route.name, {DRGData: res})
                        if (res.code.toString() === '200') {
                            if (res.data.rows.length) {
                                this.infoData.DRGsData = res.data.rows[0]
                                this.currentPage = res.data.index
                                this.total = res.data.total
                                let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                                let data = {
                                    medicalRecordSign: this.infoData.DRGsData.medicalRecordSign,
                                    hospitalTime: res.data.rows[0].hospitalTime,
                                    isLast: true,
                                    orgId: query.orgId
                                }
                                this.getMRData(data)
                                this.getMRHelperData(data)
                                this.getDataState(this.infoData.DRGsData.medicalRecordID)
                            } else {
                                this.$message.error('您搜索的病案号信息不存在')
                                this.setGetStore(this.$route.name, {keyword: ''})
                            }
                        }
                    })
                }
            },
            /**
             * 查询drg入组分析排除组
             */
            getDRGExcludelData () {
                let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                let params = {
                    department: query.department,
                    name: query.name,
                    surgeryCode: query.surgeryCode,
                    diagnosisCode: query.diagnosisCode,
                    gType: query.gType,
                    exRule: query.exRule,
                    start: query.start,
                    end: query.end,
                    orgID: query.orgId,
                    pageIndex: query.pageIndex,
                    pageSize: 1,
                    keyword: query.keyword,
                    orderBy: query.orderBy
                }
                if (this.getSession(this.$route.name, 'DRGData') && this.useStoreData) {
                    this.useStoreData = false
                    let res = this.getSession(this.$route.name, 'DRGData')
                    if (res.code.toString() === '200') {
                        if (res.data.rows.length) {
                            this.infoData.DRGsData = res.data.rows[0]
                            this.currentPage = res.data.index
                            this.total = res.data.total
                            let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                            let data = {
                                medicalRecordSign: this.infoData.DRGsData.medicalRecordSign,
                                hospitalTime: res.data.rows[0].hospitalTime,
                                isLast: true,
                                orgId: query.orgId
                            }
                            this.getMRData(data)
                            this.getMRHelperData(data)
                            this.getDataState(this.infoData.DRGsData.medicalRecordID)
                        } else {
                            this.$message.error('您搜索的病案号信息不存在')
                            this.setGetStore(this.$route.name, {keyword: ''})
                        }
                    }
                } else {
                    DRGExcludelData(params).then(res => {
                        this.useStoreData = false
                        this.setSession(this.$route.name, {DRGData: res})
                        if (res.code.toString() === '200') {
                            if (res.data.rows.length) {
                                this.infoData.DRGsData = res.data.rows[0]
                                this.currentPage = res.data.index
                                this.total = res.data.total
                                let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                                let data = {
                                    medicalRecordSign: this.infoData.DRGsData.medicalRecordSign,
                                    hospitalTime: res.data.rows[0].hospitalTime,
                                    isLast: true,
                                    orgId: query.orgId
                                }
                                this.getMRData(data)
                                this.getMRHelperData(data)
                                this.getDataState(this.infoData.DRGsData.medicalRecordID)
                            } else {
                                this.$message.error('您搜索的病案号信息不存在')
                                this.setGetStore(this.$route.name, {keyword: ''})
                            }
                        }
                    })
                }
            },
            /**
             * 查询对比结果数据
             */
            getComparsResData () {
                let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                let params = {
                    rid: query.rid,
                    medicalRecordID: query.medicalRecordID,
                    drGsState: query.drGsState,
                    weightState: query.weightState,
                    weightEnd: query.weightEnd,
                    diagnosisCode: query.diagnosisCode,
                    surgeryCode: query.surgeryCode,
                    start: query.start,
                    end: query.end,
                    orgID: query.orgId,
                    pageIndex: query.pageIndex,
                    pageSize: 1,
                    keyword: query.keyword,
                    orderBy: query.orderBy
                }
                if (this.getSession(this.$route.name, 'DRGData') && this.useStoreData) {
                    this.useStoreData = false
                    let res = this.getSession(this.$route.name, 'DRGData')
                    if (res.code.toString() === '200') {
                        if (res.data.rows.length) {
                            this.infoData.DRGsData = res.data.rows[0]
                            this.currentPage = res.data.index
                            this.total = res.data.total
                            let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                            let data = {
                                medicalRecordSign: this.infoData.DRGsData.medicalRecordSign,
                                hospitalTime: res.data.rows[0].hospitalTime,
                                isLast: true,
                                orgId: query.orgId
                            }
                            this.getMRData(data)
                            this.getMRHelperData(data)
                            this.getDataState(this.infoData.DRGsData.medicalRecordID)
                        } else {
                            this.$message.error('您搜索的病案号信息不存在')
                            this.setGetStore(this.$route.name, {keyword: ''})
                        }
                    }
                } else {
                    comparsResData(params).then(res => {
                        this.useStoreData = false
                        this.setSession(this.$route.name, {DRGData: res})
                        if (res.code.toString() === '200') {
                            if (res.data.rows.length) {
                                this.infoData.DRGsData = res.data.rows[0]
                                this.currentPage = res.data.index
                                this.total = res.data.total
                                let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                                let data = {
                                    medicalRecordSign: this.infoData.DRGsData.medicalRecordSign,
                                    hospitalTime: res.data.rows[0].hospitalTime,
                                    isLast: true,
                                    orgId: query.orgId
                                }
                                this.getMRData(data)
                                this.getMRHelperData(data)
                                this.getDataState(this.infoData.DRGsData.medicalRecordID)
                            } else {
                                this.$message.error('您搜索的病案号信息不存在')
                                this.setGetStore(this.$route.name, {keyword: ''})
                            }
                        }
                    })
                }
            },
            /**
             * 查询结算列表数据
             */
            getBillingListData () {
                let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                let params = {
                    rid: query.rid,
                    medicalRecordID: query.medicalRecordID,
                    state: query.state,
                    drgCodeName: query.drgCodeName,
                    weightStart: query.weightStart,
                    weightEnd: query.weightEnd,
                    start: query.start,
                    end: query.end,
                    orgID: query.orgId,
                    pageIndex: query.pageIndex,
                    pageSize: 1,
                    keyword: query.keyword,
                    orderBy: query.orderBy
                }
                if (this.getSession(this.$route.name, 'DRGData') && this.useStoreData) {
                    this.useStoreData = false
                    let res = this.getSession(this.$route.name, 'DRGData')
                    if (res.code.toString() === '200') {
                        if (res.data.rows.length) {
                            this.infoData.DRGsData = res.data.rows[0]
                            this.currentPage = res.data.index
                            this.total = res.data.total
                            let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                            let data = {
                                medicalRecordSign: this.infoData.DRGsData.medicalRecordSign,
                                hospitalTime: res.data.rows[0].hospitalTime,
                                isLast: true,
                                orgId: query.orgId
                            }
                            this.getMRData(data)
                            this.getMRHelperData(data)
                            this.getDataState(this.infoData.DRGsData.medicalRecordID)
                        } else {
                            this.$message.error('您搜索的病案号信息不存在')
                            this.setGetStore(this.$route.name, {keyword: ''})
                        }
                    }
                } else {
                    billingListData(params).then(res => {
                        this.useStoreData = false
                        this.setSession(this.$route.name, {DRGData: res})
                        if (res.code.toString() === '200') {
                            if (res.data.rows.length) {
                                this.infoData.DRGsData = res.data.rows[0]
                                this.currentPage = res.data.index
                                this.total = res.data.total
                                let query = JSON.parse(JSON.stringify(this.$store.state.search.searchForm[this.$route.name]))
                                let data = {
                                    medicalRecordSign: this.infoData.DRGsData.medicalRecordSign,
                                    hospitalTime: res.data.rows[0].hospitalTime,
                                    isLast: true,
                                    orgId: query.orgId
                                }
                                this.getMRData(data)
                                this.getMRHelperData(data)
                                this.getDataState(this.infoData.DRGsData.medicalRecordID)
                            } else {
                                this.$message.error('您搜索的病案号信息不存在')
                                this.setGetStore(this.$route.name, {keyword: ''})
                            }
                        }
                    })
                }
            },
            /**
             * 查询病案详情
             * @param data 请求参数
             */
            getMRData (data) {
                if (this.getSession(this.$route.name, 'MRTableData') && this.useStoreTableData) {
                    this.useStoreTableData = false
                    let res = this.getSession(this.$route.name, 'MRTableData')
                    this.emptyText = '暂无数据'
                    if (res.code.toString() === '200') {
                        this.infoData = {
                            ...this.infoData,
                            ...JSON.parse(res.data),
                            index: this.currentPage,
                            count: this.total
                        }
                    }
                } else {
                    MRTableData(data).then(res => {
                        this.useStoreTableData = false
                        this.setSession(this.$route.name, {MRTableData: res})
                        if (res.code.toString() === '200') {
                            this.infoData = {
                                ...this.infoData,
                                ...JSON.parse(res.data),
                                index: this.currentPage,
                                count: this.total
                            }
                        }
                    })
                }
            },
            /**
             * 查询小助手质控信息
             * @param data 请求参数
             */
            getMRHelperData (data) {
                if (this.getSession(this.$route.name, 'MRHelperData') && this.useStoreHelperData) {
                    this.useStoreHelperData = false
                    let res = this.getSession(this.$route.name, 'MRHelperData')
                    this.emptyText = '暂无数据'
                    if (res.code.toString() === '200') {
                        let data = res.data
                        delete data.medicalRecordID
                        this.infoData = {
                            ...this.infoData,
                            ...data,
                            index: this.currentPage,
                            count: this.total,
                            noQC: Boolean(res.data.medicalRecordID)
                        }
                        this.getHelper()
                    }
                } else {
                    MRHelperData(data).then(res => {
                        this.useStoreHelperData = false
                        this.setSession(this.$route.name, {MRHelperData: res})
                        if (res.code.toString() === '200') {
                            let data = res.data
                            if (!data.medicalRecordID) delete data.medicalRecordID
                            this.infoData = {
                                ...this.infoData,
                                ...data,
                                index: this.currentPage,
                                count: this.total,
                                noQC: Boolean(!res.data.medicalRecordID)
                            }
                            this.getHelper()
                        }
                    })
                }
            },
            /**
             * 获取病案审核记录和收藏
             * @param medicalRecordID 病案号
             */
            getDataState (medicalRecordID) {
                let params = {
                    medicalRecordID
                }
                if (this.getSession(this.$route.name, 'getMRStatDRG') && this.useStoreMRState) {
                    this.useStoreMRState = false
                    let res = this.getSession(this.$route.name, 'getMRStatDRG')
                    if (res.code.toString() === '200') {
                        this.infoData.resExamine = res.data.resExamine
                    }
                } else {
                    getMRStatDRG(params).then(res => {
                        if (res.code.toString() === '200') {
                            this.infoData.resExamine = res.data.resExamine
                            this.useStoreMRState = false
                        }
                    })
                }
            },
            /**
             * 获取小助手数据
             */
            getHelper () {
                this.$nextTick(() => {
                    this.$refs.infoTool.getHelperData()
                })
            }
        },
        components: {
            InfoHead,
            InfoTable,
            InfoTool
        },
        beforeDestroy () {
            window.onresize = null
        }
    }
</script>

<style lang="scss" scoped>
    .medical-records-info-container {
        padding-top: 3px;
        .info-content {
            padding: 10px;
            background: #fff;
            overflow-y: auto;
        }
    }
</style>
